package org.example.bookstore.service.impl;

import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.mapper.OrderMapper;
import org.example.bookstore.pojo.DO.Order;
import org.example.bookstore.pojo.DTO.DetailOrder;
import org.example.bookstore.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    /*
     * 生成订单
     * */
    @Override
    public ResultVO<?> addOrder(Order order) {
        order.setCreateTime(LocalDateTime.now());
        order.setUpdateTime(LocalDateTime.now());
        order.setPayStatus(1);
        int i=orderMapper.addOrder(order);
        if (i==0){
            return ResultVO.error();
        }
        return  ResultVO.success("添加成功");
    }
    /*
     * 的订单查询  根据用户id查询所有订单信息
     * */
    @Override
    public ResultVO<?> getOrderList(Integer id) {
        List<DetailOrder> OrderList=orderMapper.selectOrdersByUserId(id);
        if (OrderList!=null){
            return ResultVO.success("查询成功",OrderList);
        }
        return ResultVO.error();
    }
    /*
     * 根据评论id删除订单
     * */
    @Override
    public ResultVO<?> deleteOrder(Integer id) {
        int isdelete=orderMapper.deleteOrderById(id);
        if (isdelete==0){
            return ResultVO.error();
        }
        return ResultVO.success("删除成功");
    }

}
